package com.wyzz.hr.shift;

import java.math.BigDecimal;
import java.util.*;
import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.wyzz.hr.bo.IAttdoriginaldataBO;
import com.wyzz.hr.bo.IEmpshiftBo;
import com.wyzz.hr.bo.IOvertimerequestBo;
import com.wyzz.hr.bo.impl.ExaminDateUtil;
import com.wyzz.hr.dao.ILeaverequestDAO;
import com.wyzz.hr.pojo.Attdoriginaldata;
import com.wyzz.hr.pojo.Attendshift;
import com.wyzz.hr.pojo.Employee;
import com.wyzz.hr.pojo.Leaverequest;
import com.wyzz.hr.pojo.Overtimerequest;
import com.wyzz.hr.spring.SpringBeanFactory;
import com.wyzz.hr.support.AttendDailyMemory;
import com.wyzz.hr.util.DatabaseSysConfigManager;
import com.wyzz.hr.util.DateUtil;
import com.wyzz.hr.util.StringUtil;

public class AttendDailyHandler {

	public AttendDailyHandler() {
		msgError1 = "\u672A\u5237\u5361\uFF0C\u7F3A\u52E4";
		msgError2 = "\u65E0\u73ED\u6B21\uFF0C\u6709\u4E00\u6B21\u5237\u5361";
		msgError3 = "{0}\u5FD8\u8BB0\u5237\u5361";
		msgError4 = "\u65E0\u73ED\u6B21\u65E0\u52A0\u73ED\uFF0C\u6709\u5237\u5361";
		msgError5 = "\u5168\u5929\u8BF7\u5047\u65E0\u52A0\u73ED\uFF0C\u6709\u5237\u5361";
		msgStrOver = "\u52A0\u73ED";
		msgStrLate = "\u8FDF\u5230";
		msgStrEarly = "\u65E9\u9000";
		msgStrAbsent = "\u7F3A\u52E4";
		hourToDayConvStr = null;
		zero = new BigDecimal(0);
		unnomalColor = "#FF0000";
		absentConfigStr = "120";
		or_BO = (IOvertimerequestBo) SpringBeanFactory
				.getBean("overtimerequestBO");
		empshiftBo = (IEmpshiftBo) SpringBeanFactory.getBean("empshiftBO");
		originaldataBo = (IAttdoriginaldataBO) SpringBeanFactory
				.getBean("attdoriginaldataBO");
	}

	public List generateRecords() {
		if (empList == null)
			empList = new ArrayList(0);
		if (startDate == null)
			startDate = new Date();
		if (endDate == null)
			endDate = new Date();
		sysConfigProperties = DatabaseSysConfigManager.getInstance()
				.getProperties();
		String calcDayConfig = (String) sysConfigProperties
				.get("sys.examin.hourtoday.mode");
		if ("0".equals(calcDayConfig))
			hourToDayConvStr = (String) sysConfigProperties
					.get("sys.shift.card.calcday");
		else
			hourToDayConvStr = (String) sysConfigProperties
					.get("sys.examin.leave.mode");
		Map attendDailyMap = initRecords(startDate, endDate, empList);
		Map lrMap = provideLeaveRequestData(startDate, endDate, empList);
		Map orMap = or_BO.provideOvertimeRequestData(startDate, endDate,
				empList);
		Map originalDataMap = originaldataBo.provideOriginalDataMap(startDate,
				endDate, empList);
		List records = calcRecords(attendDailyMap, originalDataMap, lrMap,
				orMap);
		return records;
	}

	private Map initRecords(Date start, Date end, List empList) {
		String empIds[] = new String[empList.size()];
		for (int i = 0; empList != null && i < empList.size(); i++)
			empIds[i] = ((Employee) empList.get(i)).getId();

		Map empShiftMap = empshiftBo.provideEmpShiftData(empIds, start, end);
		empshiftBo.provideDefaultShift(empShiftMap, start, end, empList);
		Map memoryDataMap = new HashMap();
		Calendar calendar = Calendar.getInstance();
		Date compareDateObj = (Date) start.clone();
		calendar.setTime(compareDateObj);
		for (; compareDateObj.compareTo(end) <= 0; compareDateObj = calendar
				.getTime()) {
			Iterator i$ = empList.iterator();
			do {
				if (!i$.hasNext())
					break;
				Employee employee = (Employee) i$.next();
				if ((employee.getEmpStatus().intValue() != 0 || employee
						.getEmpTerminateDate() != null
						&& compareDateObj.compareTo(employee
								.getEmpTerminateDate()) <= 0)
						&& compareDateObj.compareTo(employee.getEmpJoinDate()) >= 0) {
					String dateString = DateUtil.formatDate(compareDateObj);
					AttendDailyMemory bean = new AttendDailyMemory();
					bean.setEmpObj(employee);
					bean.setEmpName(employee.getEmpName());
					bean.setEmpDistinctNo(employee.getEmpDistinctNo());
					bean.setEmpId(employee.getId());
					bean.setExaminDate(compareDateObj);
					Attendshift shift = (Attendshift) empShiftMap
							.get((new StringBuilder()).append(employee.getId())
									.append(dateString).toString());
					if (shift != null) {
						bean.setShiftName(shift.getAttsName());
						bean.setShiftId(shift.getId());
						bean.setShift(shift);
					}
					memoryDataMap.put((new StringBuilder()).append(
							employee.getId()).append(dateString).toString(),
							bean);
				}
			} while (true);
			calendar.add(5, 1);
		}

		return memoryDataMap;
	}

	private Map provideLeaveRequestData(Date startDate, Date endDate, List emps) {
		Date tempEndDate = DateUtil.dateAdd(endDate, 2);
		Integer status[] = { Integer.valueOf(15), Integer.valueOf(16) };
		ILeaverequestDAO dao = (ILeaverequestDAO) SpringBeanFactory
				.getBean("leaverequestDAO");
		DetachedCriteria detachedCrteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Leaverequest.class);
		detachedCrteria.createAlias(Leaverequest.PROP_LR_LT_NO, "lrLtNo", 1);
		if (emps.size() > 0 && emps.size() <= 500)
			detachedCrteria.add(Restrictions.in("lrEmpNo", emps));
		detachedCrteria.add(Restrictions
				.in(Leaverequest.PROP_LR_STATUS, status));
		detachedCrteria.add(Restrictions.or(Restrictions.or(Restrictions.and(
				Restrictions.ge(Leaverequest.PROP_LR_START_DATE, startDate),
				Restrictions.lt(Leaverequest.PROP_LR_START_DATE, tempEndDate)),
				Restrictions.and(Restrictions.ge(Leaverequest.PROP_LR_END_DATE,
						startDate), Restrictions.lt(
						Leaverequest.PROP_LR_END_DATE, tempEndDate))),
				Restrictions.and(Restrictions.lt(
						Leaverequest.PROP_LR_START_DATE, startDate),
						Restrictions.ge(Leaverequest.PROP_LR_END_DATE,
								tempEndDate))));
		List lrList = dao.findByCriteria(detachedCrteria);
		Map empLrMap = new HashMap();
		List tempLrList = null;
		Leaverequest lr;
		for (Iterator i$ = lrList.iterator(); i$.hasNext(); tempLrList.add(lr)) {
			lr = (Leaverequest) i$.next();
			tempLrList = (List) empLrMap.get(lr.getLrEmpNo().getId());
			if (tempLrList == null) {
				tempLrList = new ArrayList();
				empLrMap.put(lr.getLrEmpNo().getId(), tempLrList);
			}
		}

		return empLrMap;
	}

	private List calcRecords(Map map, Map originalDataMap, Map lrMap, Map orMap) {
		List dataList = new ArrayList();
		Set hashSet = map.keySet();
		Iterator iterator = hashSet.iterator();
		do {
			if (!iterator.hasNext())
				break;
			String key = (String) iterator.next();
			AttendDailyMemory bean = (AttendDailyMemory) map.get(key);
			List origDataList = (List) originalDataMap.get(key);
			List lrList = (List) lrMap.get(bean.getEmpId());
			List orList = (List) orMap.get(key);
			getDailyLeaves(bean, lrList, sysConfigProperties);
			getDailyOrHours(bean, orList);
			boolean result = computeOnOffDutyTime(dataList, bean, lrList,
					orList, origDataList);
			if (result) {
				calcOthers(bean, sysConfigProperties);
				checkOverOneDay(bean);
				dataList.add(bean);
			}
		} while (true);
		return dataList;
	}

	private boolean computeOnOffDutyTime(List dataList, AttendDailyMemory bean,
			List lrList, List orList, List origDataList) {
		gernerateNewAttdSessionWithLR(bean, lrList);
		gernerateNewAttdSessionWithOR(bean, orList);
		if (bean.getEmpObj().getEmpShiftType().intValue() != 0) {
			String temp = getOnOffDutyTime(bean, origDataList,
					sysConfigProperties);
			if ("shouldNotCard".equals(temp)) {
				dataList.add(bean);
				return false;
			}
		}
		return true;
	}

	private void checkOverOneDay(AttendDailyMemory bean) {

	}

	private void getDailyLeaves(AttendDailyMemory bean, List lrList, Map sysMap) {
		if (bean.getShift() == null)
			return;
		if (lrList == null)
			return;
		int minutes = 0;
		BigDecimal totalHours = new BigDecimal(0);
		BigDecimal totalDays = new BigDecimal(0);
		Iterator i$ = lrList.iterator();
		do {
			if (!i$.hasNext())
				break;
			Leaverequest lr = (Leaverequest) i$.next();
			Integer key = lr.getLrLtNo().getLtSpecialCat();
			minutes = ExaminDateUtil.minutesInShift(lr.getLrStartDate(), lr
					.getLrEndDate(), bean.getExaminDate(), bean.getShift()
					.getAttsSession());
			BigDecimal hours = ExaminDateUtil.convertMinutesToHours(
					new BigDecimal(minutes), (String) sysMap
							.get("sys.shift.card.calchour"));
			BigDecimal days = ExaminDateUtil.convertHourToDay(hours,
					hourToDayConvStr, bean.getShift());
			if (bean.getLeaveHoursMap().containsKey(key))
				bean.getLeaveHoursMap().put(
						key,
						((BigDecimal) bean.getLeaveHoursMap().get(key))
								.add(hours));
			else
				bean.getLeaveHoursMap().put(key, hours);
			if (bean.getLeaveDaysMap().containsKey(key))
				bean.getLeaveDaysMap().put(
						key,
						((BigDecimal) bean.getLeaveDaysMap().get(key))
								.add(days));
			else
				bean.getLeaveDaysMap().put(key, days);
			if (key.intValue() != 8 && key.intValue() != 9) {
				totalHours = totalHours.add(hours);
				totalDays = totalDays.add(days);
			}
		} while (true);
		bean.setLeaveHours(totalHours);
		bean.setLeaveDays(totalDays);
	}

	private void getDailyOrHours(AttendDailyMemory bean, List orList) {
		if (orList == null)
			return;
		BigDecimal orHours = new BigDecimal(0);
		Iterator iterator = orList.iterator();
		do {
			if (!iterator.hasNext())
				break;
			Overtimerequest or = (Overtimerequest) iterator.next();
			Date orDate = or.getOrShiftDate();
			if (orDate.equals(bean.getExaminDate())) {
				orHours = orHours.add(or.getOrTotalHours());
				String key = or.getOrOtNo().getOtNo();
				if (bean.getOrHoursMap().containsKey(key))
					bean.getOrHoursMap().put(
							key,
							((BigDecimal) bean.getOrHoursMap().get(key)).add(or
									.getOrTotalHours()));
				else
					bean.getOrHoursMap().put(key, or.getOrTotalHours());
			}
		} while (true);
		bean.setOvertimeHours(orHours);
	}

	private String getOnOffDutyTime(AttendDailyMemory bean, List origDataList,
			Map sysMap) {
		if (bean.getShift() != null
				&& !StringUtils.isEmpty(bean.getShift().getNewAttdSession())) {
			String startMinute = (String) sysMap.get("sys.shift.start.minute");
			String endMinute = (String) sysMap.get("sys.shift.end.minute");
			Date onOffTimes[] = ExaminDateUtil.getShiftArr(
					bean.getExaminDate(), bean.getShift().getNewAttdSession());
			Date onTime = DateUtil.dateTimeAdd(onOffTimes[0], -Integer
					.parseInt(startMinute), 12);
			Date offTime = DateUtil.dateTimeAdd(onOffTimes[1], Integer
					.parseInt(endMinute), 12);
			deleteInvalidRec(origDataList, (String) sysMap
					.get("sys.shift.cardrepeat.minute"), onTime, offTime);
		}
		if (origDataList == null || origDataList.size() == 0) {
			if (bean.getShift() == null)
				return null;
			if (bean.getLeaveHours().compareTo(
					bean.getShift().getAttsWorkingHour()) >= 0) {
				return null;
			} else {
				bean.setComments(msgError1);
				bean.setDisplayColor(unnomalColor);
				return null;
			}
		}
		if (origDataList.size() == 1) {
			bean.setOnDutyTime(((Attdoriginaldata) origDataList.get(0))
					.getAodCardTime());
			bean.setOffDutyTime(((Attdoriginaldata) origDataList.get(0))
					.getAodCardTime());
			if (bean.getShift() == null)
				bean.setComments(msgError2);
			else if (judgeCard(bean, (Attdoriginaldata) origDataList.get(0)) == 1)
				bean.setComments(StringUtil.message(msgError3,
						new Object[] { "\u4E0B\u73ED" }));
			else
				bean.setComments(StringUtil.message(msgError3,
						new Object[] { "\u4E0A\u73ED" }));
			bean.setDisplayColor(unnomalColor);
			return null;
		}
		bean.setOnDutyTime(getMinorMaxDateData(origDataList, "min"));
		bean.setOffDutyTime(getMinorMaxDateData(origDataList, "max"));
		if (bean.getShift() == null) {
			bean.setComments(msgError4);
			bean.setDisplayColor(unnomalColor);
			return "shouldNotCard";
		}
		if (bean.getShift() != null
				&& StringUtils.isEmpty(bean.getShift().getNewAttdSession())) {
			bean.setComments(msgError5);
			bean.setDisplayColor(unnomalColor);
			return "shouldNotCard";
		} else {
			return null;
		}
	}

	private int judgeCard(AttendDailyMemory bean, Attdoriginaldata data) {
		String session = bean.getShift().getNewAttdSession() == null ? bean
				.getShift().getNewAttdSession() : bean.getShift()
				.getNewAttdSession();
		String sessionArr[] = session.split(",");
		String startTime = sessionArr[0].split("-")[0];
		String endTime = sessionArr[sessionArr.length - 1].split("-")[1];
		Date oughtOnDutyTime = DateUtil.parseDateByFormat((new StringBuilder())
				.append(DateUtil.formatDate(bean.getExaminDate())).append(" ")
				.append(startTime).toString(), "yyyy-MM-dd HH:mm");
		Date oughtOffDutyTime = DateUtil.parseDateByFormat(
				(new StringBuilder()).append(
						DateUtil.formatDate(bean.getExaminDate())).append(" ")
						.append(endTime).toString(), "yyyy-MM-dd HH:mm");
		return data.getAodCardTime().getTime() - oughtOnDutyTime.getTime() > oughtOffDutyTime
				.getTime()
				- data.getAodCardTime().getTime() ? 2 : 1;
	}

	private void gernerateNewAttdSessionWithLR(AttendDailyMemory bean,
			List lrList) {
		if (bean.getShift() == null)
			return;
		String newAttdSession = bean.getShift().getAttsSession();
		for (int i = 0; lrList != null && i < lrList.size(); i++) {
			Leaverequest lr = (Leaverequest) lrList.get(i);
			String cut = (new StringBuilder()).append(
					StringUtil.getSessionTimeByExainDate(bean.getExaminDate(),
							lr.getLrStartDate())).append("#").append(
					StringUtil.getSessionTimeByExainDate(bean.getExaminDate(),
							lr.getLrEndDate())).toString();
			newAttdSession = StringUtil
					.cutSegmentFromShift(newAttdSession, cut);
		}

		bean.getShift().setNewAttdSession(newAttdSession);
		List cutList = new ArrayList();
		if (newAttdSession.length() == 0)
			return;
		String newSessionArr[] = newAttdSession.split(",");
		String arr$[] = newSessionArr;
		int len$ = arr$.length;
		for (int i$ = 0; i$ < len$; i$++) {
			String tempCut = arr$[i$];
			String tempCutArr[] = tempCut.split("-");
			Date dateArr[] = {
					DateUtil.parseDateByFormat((new StringBuilder()).append(
							DateUtil.formatDate(bean.getExaminDate())).append(
							" ").append(tempCutArr[0]).toString(),
							"yyyy-MM-dd HH:mm"),
					DateUtil.parseDateByFormat((new StringBuilder()).append(
							DateUtil.formatDate(bean.getExaminDate())).append(
							" ").append(tempCutArr[1]).toString(),
							"yyyy-MM-dd HH:mm") };
			cutList.add(dateArr);
		}

		bean.getShift().setNewAttdSessionList(cutList);
	}

	private void gernerateNewAttdSessionWithOR(AttendDailyMemory bean,
			List orList) {
		if (orList == null || orList.size() == 0)
			return;
		if (bean.getShift() == null) {
			bean.setShift(new Attendshift(null, msgStrOver, null, null, null));
			bean.setShiftName(msgStrOver);
		}
		empshiftBo.changeAttdSessionWithOR(bean.getExaminDate(), bean
				.getShift(), orList);
		if (bean.getShift().getAttsWorkingHour() == null)
			bean.getShift().setAttsWorkingHour(zero);
	}

	private void calcOthers(AttendDailyMemory bean, Map sysMap) {
		if (bean.getShift() == null)
			return;
		bean.setOughtDutyHours(bean.getShift().getAttsWorkingHour());
		bean.setOughtDutyDays(ExaminDateUtil.convertHourToDay(bean
				.getOughtDutyHours(), hourToDayConvStr, bean.getShift()));
		if (bean.getEmpObj().getEmpShiftType().intValue() == 0)
			return;
		if (bean.getOnDutyTime() == null
				|| bean.getOffDutyTime() == null
				|| bean.getOnDutyTime().getTime() == bean.getOffDutyTime()
						.getTime()) {
			bean.setAbsentHours(bean.getShift().getAttsWorkingHour().subtract(
					bean.getLeaveHours()));
			bean.setAbsentDays(ExaminDateUtil.convertHourToDay(bean
					.getAbsentHours(), hourToDayConvStr, bean.getShift()));
			return;
		}
		String config = (String) sysMap.get("sys.examin.absent.minute");
		BigDecimal absentConfig = new BigDecimal(config == null
				|| config.trim().length() <= 0 ? absentConfigStr : config);
		BigDecimal lateMinutes = new BigDecimal(0);
		BigDecimal earlyMinutes = new BigDecimal(0);
		BigDecimal absentDayOrHours = new BigDecimal(0);
		String lateMinutes_str = (String) sysMap.get("sys.shift.late.minute");
		String earlyleave_str = (String) sysMap
				.get("sys.shift.earlyleave.minute");
		BigDecimal lateMinutes_b = new BigDecimal(lateMinutes_str.split(",")[0]);
		BigDecimal earlyleave_b = new BigDecimal(earlyleave_str.split(",")[0]);
		List newSessList = bean.getShift().getNewAttdSessionList();
		if (newSessList == null)
			return;
		Date oughtOnDutyTime = ((Date[]) newSessList.get(0))[0];
		Date oughtOffDutyTime = ((Date[]) newSessList
				.get(newSessList.size() - 1))[1];
		Date onDutyTime = bean.getOnDutyTime();
		Date offDutyTime = bean.getOffDutyTime();
		lateMinutes = new BigDecimal((onDutyTime.getTime() - oughtOnDutyTime
				.getTime()) / 60000L);
		if (lateMinutes.compareTo(lateMinutes_b) >= 0) {
			long minutesInSpare = getShiftSpareInTimeSession(bean.getShift(),
					bean.getExaminDate(), oughtOnDutyTime, onDutyTime);
			lateMinutes = lateMinutes.subtract(new BigDecimal(minutesInSpare));
			bean.setLateMinutes(lateMinutes);
			bean.setComments(bean.getComments() == null
					|| bean.getComments().trim().length() <= 0 ? msgStrLate
					: (new StringBuilder()).append(bean.getComments()).append(
							",").append(msgStrLate).toString());
			bean.setDisplayColor(unnomalColor);
		} else {
			lateMinutes = zero;
		}
		earlyMinutes = new BigDecimal((oughtOffDutyTime.getTime() - offDutyTime
				.getTime()) / 60000L);
		if (earlyMinutes.compareTo(earlyleave_b) >= 0) {
			long minutesInSpare = getShiftSpareInTimeSession(bean.getShift(),
					bean.getExaminDate(), offDutyTime, oughtOffDutyTime);
			earlyMinutes = earlyMinutes
					.subtract(new BigDecimal(minutesInSpare));
			bean.setEarlyMinutes(earlyMinutes);
			bean.setComments(bean.getComments() == null
					|| bean.getComments().trim().length() <= 0 ? msgStrEarly
					: (new StringBuilder()).append(bean.getComments()).append(
							",").append(msgStrEarly).toString());
			bean.setDisplayColor(unnomalColor);
		} else {
			earlyMinutes = zero;
		}
		if (lateMinutes.add(earlyMinutes).compareTo(absentConfig) >= 0) {
			absentDayOrHours = ExaminDateUtil.convertMinutesToHours(
					new BigDecimal(lateMinutes.add(earlyMinutes).longValue()),
					(String) sysMap.get("sys.shift.card.calchour"));
			bean.setAbsentHours(absentDayOrHours);
			absentDayOrHours = ExaminDateUtil.convertHourToDay(bean
					.getAbsentHours(), hourToDayConvStr, bean.getShift());
			if (absentDayOrHours.compareTo(zero) == 0)
				bean.setAbsentDays(new BigDecimal(0.5D));
			else
				bean.setAbsentDays(absentDayOrHours);
			bean.setComments(msgStrAbsent);
			bean.setDisplayColor(unnomalColor);
			bean.setLateMinutes(zero);
			bean.setEarlyMinutes(zero);
		}
	}

	private long getShiftSpareInTimeSession(Attendshift shift, Date examinDate,
			Date start, Date end) {
		long minutes = 0L;
		List cutList = shift.getNewAttdSessionList();
		if (cutList == null)
			return minutes;
		if (cutList.size() == 1) {
			long commentM = getCommenTimes(((Date[]) cutList.get(0))[0],
					((Date[]) cutList.get(0))[1], start, end).longValue();
			if (commentM > 0L)
				return (end.getTime() - start.getTime()) / 60000L - commentM;
			else
				return (end.getTime() - start.getTime()) / 60000L;
		}
		String spareSession = "";
		Date cutArr[] = null;
		Date cutArrNext[] = null;
		for (int i = 0; i <= cutList.size() - 2; i++) {
			cutArr = (Date[]) cutList.get(i);
			cutArrNext = (Date[]) cutList.get(i + 1);
			String time1 = DateUtil
					.formatDateToS(cutArr[1], "yyyy-MM-dd HH:mm").substring(11);
			String time2 = DateUtil.formatDateToS(cutArrNext[0],
					"yyyy-MM-dd HH:mm").substring(11);
			spareSession = (new StringBuilder()).append(spareSession).append(
					time1).append("-").append(time2).append(",").toString();
		}

		minutes = ExaminDateUtil.minutesInShift(start, end, examinDate,
				spareSession.substring(0, spareSession.length() - 1));
		return minutes;
	}

	private Date getMinorMaxDateData(List origDataList, String minormax) {
		Attdoriginaldata data = (Attdoriginaldata) origDataList.get(0);
		Date maxDate = data.getAodCardTime();
		Date minDate = data.getAodCardTime();
		Iterator i$ = origDataList.iterator();
		do {
			if (!i$.hasNext())
				break;
			Attdoriginaldata dataTemp = (Attdoriginaldata) i$.next();
			Date currDate = dataTemp.getAodCardTime();
			if (currDate.getTime() > maxDate.getTime())
				maxDate = currDate;
			if (currDate.getTime() < minDate.getTime())
				minDate = currDate;
		} while (true);
		if ("min".equals(minormax))
			return minDate;
		else
			return maxDate;
	}

	private void deleteInvalidRec(List origList, String configValue,
			Date onTime_b, Date offTime_a) {
		if (origList == null || origList.size() == 0)
			return;
		Long minute = Long.valueOf(Long.parseLong(configValue));
		Attdoriginaldata data = null;
		Attdoriginaldata data1 = null;
		Date currentDate = null;
		Date currentDate1 = null;
		Iterator iterator = origList.iterator();
		do {
			if (!iterator.hasNext())
				break;
			data = (Attdoriginaldata) iterator.next();
			if (data.getAodCardTime().getTime() < onTime_b.getTime()
					|| offTime_a.getTime() < data.getAodCardTime().getTime())
				iterator.remove();
		} while (true);
		label0: for (int i = 0; origList != null && i < origList.size(); i++) {
			data = (Attdoriginaldata) origList.get(i);
			currentDate = data.getAodCardTime();
			if (currentDate == null)
				continue;
			iterator = origList.iterator();
			do {
				do {
					do {
						if (!iterator.hasNext())
							continue label0;
						data1 = (Attdoriginaldata) iterator.next();
					} while (data1 != null && data != null
							&& data1.getAodId().equals(data.getAodId()));
					currentDate1 = data1.getAodCardTime();
				} while (Math.abs(currentDate1.getTime()
						- currentDate.getTime()) >= minute.longValue() * 60L * 1000L);
				iterator.remove();
			} while (true);
		}

	}

	public Long getCommenTimes(Date on, Date off, Date start, Date end) {
		long seconds = 0L;
		if (end.getTime() >= on.getTime() && start.getTime() <= off.getTime())
			if (start.getTime() < on.getTime() && off.getTime() < end.getTime())
				seconds = (off.getTime() - on.getTime()) / 1000L;
			else if (start.getTime() < on.getTime()
					&& on.getTime() < end.getTime())
				seconds = (end.getTime() - on.getTime()) / 1000L;
			else if (on.getTime() <= start.getTime()
					&& end.getTime() <= off.getTime())
				seconds = (end.getTime() - start.getTime()) / 1000L;
			else if (start.getTime() < off.getTime()
					&& off.getTime() < end.getTime())
				seconds = (off.getTime() - start.getTime()) / 1000L;
		return Long.valueOf(seconds / 60L);
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public void setEmpList(List empList) {
		this.empList = empList;
	}

	public String getHourToDayConvStr() {
		return hourToDayConvStr;
	}

	public void setHourToDayConvStr(String hourToDayConvStr) {
		this.hourToDayConvStr = hourToDayConvStr;
	}

	private String msgError1;
	private String msgError2;
	private String msgError3;
	private String msgError4;
	private String msgError5;
	private String msgStrOver;
	private String msgStrLate;
	private String msgStrEarly;
	private String msgStrAbsent;
	private Date startDate;
	private Date endDate;
	private List empList;
	private Map sysConfigProperties;
	private String hourToDayConvStr;
	public BigDecimal zero;
	public String unnomalColor;
	private String absentConfigStr;
	IOvertimerequestBo or_BO;
	IEmpshiftBo empshiftBo;
	IAttdoriginaldataBO originaldataBo;
}
